#include "RoadContext.h"


#include <QFileInfo>


#include <QDebug>

namespace kepen {
namespace core {

RoadContext::RoadContext()
    :countRoadData{0}
    ,roadData{NULL}
{
    cityRoadDao = new kepen::kemod::CityRoadDao();
}

RoadContext::~RoadContext()
{
    delete cityRoadDao;

    if(roadData){
        delete[] roadData;
        roadData = NULL;
    }


}

void RoadContext::initDataSource(sqlite3 *dbSQLite3, const QString &tableName)
{

    if(roadData){
        delete[] roadData;
        roadData = NULL;
    }

    cityRoadDao->setTableName(tableName);

    cityRoadDao->setDbSource(dbSQLite3);


    int total=0;
    kepen::kemod::RoadBean * data =cityRoadDao->selectAllRoadName(&total);
    std::vector<kepen::kemod::RoadBean*> &v = m_ListRoadName;
    v.clear();
    if(total>0)
    {
        int i=0;
        kepen::kemod::RoadBean * p = data;

        for(;i<total;++i){
            v.push_back(p);
            ++p;
        }
    }

    countRoadData = total;
    roadData = data;


}

const kepen::kemod::CityRoadDao *RoadContext::getCityRoadDao() const
{
    return cityRoadDao;
}



}
}
